import 'dart:convert';

import 'package:flutter/services.dart';
import 'package:xbaistack/model/regional.dart';

final class Consts {
  Consts._();
  static late final List<Regional> regional;

  /// Empty function constant
  static void doNothing() {}

  /// About network request
  static const request = (
    baseUrl: "https://mock.presstime.cn/mock/683e627696dd34226fe3b936/mock/",
    // baseUrl: "https://mock.presstime.cn/mock/67bb01e6b1cc73028018b014/flutter/",
    minWaitingTime: Duration(milliseconds: 500),
    cachedTime: Duration(milliseconds: 1000),
    sendTimeout: Duration(seconds: 5),
    connectTimeout: Duration(seconds: 5),
    receiveTimeout: Duration(seconds: 5),
    successCode: 200,
    pageSize: 10,
  );

  static Future<void> ensureInitialized() async {
    final data = await rootBundle.loadString("assets/city.json");
    final items = jsonDecode(data) as List<dynamic>;
    regional = items.map((e) => Regional.fromJson(e)).toList();
  }
}
